In [9]:
2121
1 + 1*2 + 5**2
Out[9]:
28
In [16]:
a = 2
b = 2
c = a
In [17]:
a
Out[17]:
2
In [18]:
b
Out[18]:
2
In [19]:
c
Out[19]:
2
In [20]:
a = 3
In [21]:
c
Out[21]:
2
In [22]:
a = [1, 2, 3]
In [23]:
type(c)
Out[23]:
int
In [24]:
b = a
In [25]:
a[0] = 5
In [26]:
a
Out[26]:
[5, 2, 3]
In [27]:
b
Out[27]:
[5, 2, 3]
In [32]:
100000 + 2000000
Out[32]:
2100000
In [33]:
_
Out[33]:
2100000
In [30]:
34**44
Out[30]:
24270143818756646910938690328635932139549939061012471930088572583936
In [46]:
a = 100
b = 100
In [47]:
a is b
Out[47]:
True
In [53]:
a = [1, "aaa", 3]
In [54]:
a + a
Out[54]:
[1, 'aaa', 3, 1, 'aaa', 3]
In [56]:
a = [[1, 2, 3],
     [10, 20, 30]]
In [62]:
b = a[0]
In [63]:

b[0]
Out[63]:
1
In [64]:
import numpy
In [66]:
numpy.gradient?
In [71]:
a = numpy.array([1, 2, 3])
In [72]:
a
Out[72]:
array([1, 2, 3])
In [73]:
a.shape
Out[73]:
(3,)
In [75]:
e = a[0]
In [76]:
type(e)
Out[76]:
numpy.int64
In [77]:
a.shape
Out[77]:
(3,)
In [78]:
e.shape
Out[78]:
()
In [79]:
a = numpy.array([[1, 2, 3], [10, 20, 30]])
In [80]:
a
Out[80]:
array([[ 1,  2,  3],
       [10, 20, 30]])
In [81]:
a.shape
Out[81]:
(2, 3)
In [86]:
b = a[0]
b
Out[86]:
array([1, 2, 3])
In [85]:
b[0]
Out[85]:
1
In [88]:
%%timeit
The slowest run took 31.38 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 277 ns per loop
In [90]:
%%timeit
a[0, 0]
The slowest run took 32.69 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 148 ns per loop
In [92]:
a
Out[92]:
array([[ 1,  2,  3],
       [10, 20, 30]])
In [97]:
a[1, 0:2]
Out[97]:
array([10, 20])
In [98]:
0:2
  File "<ipython-input-98-e66af9ff3e2d>", line 1
    0:2
     ^
SyntaxError: invalid syntax

In [99]:
l = [1, 2, 3]
In [101]:
l[1:2]
Out[101]:
[2]
In [106]:
a[:, 1:2].T
Out[106]:
array([[ 2, 20]])
In [107]:
a[1, :].T
Out[107]:
array([10, 20, 30])
In [108]:
a
Out[108]:
array([[ 1,  2,  3],
       [10, 20, 30]])
In [112]:
A = numpy.matrix(a)
In [113]:
A
Out[113]:
matrix([[ 1,  2,  3],
        [10, 20, 30]])
In [123]:
a.dot(a.T)
Out[123]:
array([[  14,  140],
       [ 140, 1400]])

I can type text here

  • bullet
  • bullet

heading

\(Ax = \beta\)

In [124]:
A = numpy.array([[1, 2], [4, 2]])
In [125]:
beta = numpy.array([[2], [2]])
In [132]:
numpy.linalg.inv(A).dot(beta)
Out[132]:
array([[ 0.],
       [ 1.]])
In [131]:
numpy.linalg.solve(A, beta)
Out[131]:
array([[ 0.],
       [ 1.]])
In [133]:
A = numpy.matrix(A)
In [134]:
beta = numpy.matrix(beta)
In [136]:
A.I*beta
Out[136]:
matrix([[ 0.],
        [ 1.]])
In [137]:
import matplotlib.pyplot as plt
In [138]:
%matplotlib notebook
In [139]:
plt.plot([1, 2, 3], [1, 2, 1])
Out[139]:
[<matplotlib.lines.Line2D at 0x10b38bba8>]
In [140]:
x = numpy.linspace(0, numpy.pi*2)
In [141]:
y = numpy.sin(x)
In [142]:

plt.plot(x, y)
Out[142]:
[<matplotlib.lines.Line2D at 0x10b15b320>]
In [144]:
plt.figure()
plt.plot(x, y)
Out[144]:
[<matplotlib.lines.Line2D at 0x10ba88cf8>]
In [147]:
a = [100, 1, 3]
In [153]:
for i in range(0, len(a)):
    print(a[i])
100
1
3
In [159]:
for e in a:
    print(e)
    print("another")
print("done")
100
another
1
another
3
another
done
In [160]:
a = 20
while a > 10:
    a -= 1
In [168]:
if a > 10 and a < 3:
    print("Nope")
else:
    print("Yup")
Yup
In [170]:
a = 5
In [172]:
1 < a < 10 < 50 < 100 #=> 1<a and a < 10
Out[172]:
True
In [186]:
b = 5
In [187]:
def f(a):
    return a + b
In [188]:
f(2)
Out[188]:
7
In [190]:
b = 2
In [191]:
f(2)
Out[191]:
4
In [192]:
def functionprinter(g):
    print(g(1))
In [194]:
functionprinter(f)
3
In [196]:
len([1, 2, 3])
Out[196]:
3
In [197]:
a = len
In [198]:
a([1, 2, 3])
Out[198]:
3
In [204]:
functions = [numpy.sin, f, numpy.cos, 2]
In [226]:
for function in functions:
    print(function(1))
0.841470984808
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-226-08426fa1b189> in <module>()
      1 for function in functions:
----> 2     print(function(1))

TypeError: 'int' object is not callable
In [227]:
things = []
In [228]:
mylist = range(20)
In [229]:
for i in mylist:
    if i > 10:
        things.append(i**2)
In [230]:
things
Out[230]:
[121, 144, 169, 196, 225, 256, 289, 324, 361]
In [231]:
[i**2 for i in mylist if i > 10 ]
Out[231]:
[121, 144, 169, 196, 225, 256, 289, 324, 361]
In [233]:
things
Out[233]:
[121, 144, 169, 196, 225, 256, 289, 324, 361]
In [236]:
def f(a):
    return a + 1
In [237]:
[f(i) for i in things]
Out[237]:
[122, 145, 170, 197, 226, 257, 290, 325, 362]